package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.dto.CarDTO;
import com.woniuxy.entity.dto.ReceivableOrderDTO;
import com.woniuxy.mapper.ReceivableOrderMapper;
import com.woniuxy.service.ReceivableOrderService;
import com.woniuxy.util.PageData;
import com.woniuxy.util.ResponseData;
import com.woniuxy.util.SnowflakeIdGenerator;
import com.woniuxy.util.UserContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ReceivableOrderServiceImpl implements ReceivableOrderService {
    @Resource
    private ReceivableOrderMapper receivableOrderMapper;
    @Override
    public ResponseData<?> queryAll(PageData<ReceivableOrderDTO> pageData) {
        PageHelper.startPage(pageData.getPageNum(),pageData.getPageSize());
        List<ReceivableOrderDTO> receivableOrderDTOS = receivableOrderMapper.queryAll(pageData.getParam());
        PageInfo pageInfo = new PageInfo(receivableOrderDTOS);
        return new ResponseData<>().ok(pageInfo);
    }


    @Override
    public ResponseData<?> updateSettlementStatus(String id) {
        receivableOrderMapper.updateSettlementStatus(id);
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> addDuiZhang(ReceivableOrderDTO receivableOrderDTO) {
        Long userId = UserContext.getUserId();
        SnowflakeIdGenerator sg = new SnowflakeIdGenerator();
        String orderNum = String.valueOf(sg.nextId());
        receivableOrderDTO.setReceivableId(orderNum);
        receivableOrderDTO.setPowerUserId(userId.toString());
        receivableOrderMapper.addDuiZhang(receivableOrderDTO);
        receivableOrderMapper.updateStatus(receivableOrderDTO.getId());
        return new ResponseData<>().ok();
    }

    @Override
    public ResponseData<?> queryAll2(PageData<ReceivableOrderDTO> pageData) {
        PageHelper.startPage(pageData.getPageNum(),pageData.getPageSize());
        List<ReceivableOrderDTO> receivableOrderDTOS = receivableOrderMapper.queryAll2(pageData.getParam());
        PageInfo pageInfo = new PageInfo(receivableOrderDTOS);
        return new ResponseData<>().ok(pageInfo);
    }
}
